package com.example.springboot.demo.controller;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/response")
@Controller
public class ResponseController {
    /**
     * 返回页面
     * @return
     */
    @RequestMapping("/r1")
    public String test1(){
        return "/test1.html";
    }
    /**
     * 返回数据
     */
    @ResponseBody
    @RequestMapping("/r2")
    public String test2(){
        return "hhh";
    }
    @ResponseBody
    @RequestMapping("/r3")
    public String test3(){
        return "<h1>我是1级标题</h1>";
    }
    @ResponseBody
    @RequestMapping(value = "/r4",produces ="text/plain")
    public String test4(){
        return "<h1>我是1级标题</h1>";
    }
    @ResponseBody
    @RequestMapping(value = "/r5")
    public String setState(HttpServletResponse response){
        response.setStatus(404);
        return "出错了！";
    }
    @ResponseBody
    @RequestMapping(value = "/r6")
    public String setHeader(HttpServletResponse response){
        response.setHeader("header","header");
        return "设置Header";
    }
}
